package com.hgx.algorithm.base.comparator;


import com.hgx.algorithm.base.entity.Person;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;

public class TestComparator {
    public static void main(String[] args) {
        Person[] people = new Person[]{
                new Person(1, "哈哈哈", new Date()),
                new Person(7, "咩咩咩咩", new Date()),
                new Person(9, "上的v", new Date()),
                new Person(3, "实地调查", new Date())
        };



        Arrays.sort(people,new PersonComparatorByName());
        for (Person p:
             people) {
            System.out.println(p);
        }
        System.out.println();
        Arrays.sort(people, Comparator.comparing(Person::getId));
        for (Person p:
                people) {
            System.out.println(p);
        }
    }

    static class PersonComparatorByName implements Comparator<Person> {


        @Override
        public int compare(Person o1, Person o2) {
            return o1.getName().compareTo(o2.getName());
        }
    }

}
